HackerRank Equal
解答
code: python
import math
import os
import random
import re
import sys
#
# Complete the 'equal' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER_ARRAY arr as parameter.
#
# no. of cost to be from 1,2,5
def g(v):
n5 = v // 5
n2 = v % 5 // 2
n1 = v % 5 % 2
return n5 + n2 + n1
def equal(arr):
# Write your code here
n = len(arr) # 3
p = min(arr) # 7
dp = [0*n for _ in range(5)] for i in range(5):
for j in range(n):
if j > 0:
# print(dp)
# 2, 2, 3], 2, 3, 5, 1, 2, 4, 2, 4, 7, [2, 4, 7 return min([dpin-1 for i in range(5)]) if __name__ == '__main__':
t = int(input().strip())
for t_itr in range(t):
n = int(input().strip())
arr = list(map(int, input().rstrip().split()))
result = equal(arr)
fptr.write(str(result) + '\n')
fptr.close()
テーマ
メモ
https://www.youtube.com/watch?v=BQ3wrdxgos8